function newTarget() {
		var width = document.body.clientWidth / 3;
		var height = document.body.clientHeight / 4;
		jQuery('#newTarget').lightbox_me({
			modalCSS : {
				top : height,
				left : width
			}
		});
	}

	function closeNT() {
		jQuery('#newTarget').trigger('close');
	}

	function selectIndex(o) {
		$(document.getElementById(preSelectIndex)).css("background", "#fff");
		preSelectIndex = o.id;
		var idx = nameMap[o.innerHTML];
		if (!idx) {
			nameMap[o.innerHTML] = preSelectIndex;
		}
		$(o).css("background", "#009cff");
	}

	function quickMove(o) {
		selectIndex(o);
		moveIndex();
	};

	function moveIndex() {
		if (preSelectIndex) {
			insertAtCursor("#" + $(document.getElementById(preSelectIndex)).html() + "#");
		} else {
			alert("请先选择指标");
		}
	}

	function addCustom() {
		var cstmName = $.trim($("#cstmName").val());
		if (!cstmName) {
			alert("必须输入自定义指标名称");
			return;
		}
		if (!/^[\u4e00-\u9fa5a-zA-Z0-9_]+$/.test(cstmName)) {
			alert("只能输入数字、字母、下划线或者汉字");
			return;
		}
		if (cstmName.length > 50) {
			alert("最多只能输入50个字");
			return;
		}
		if (cstmName in nameMap) {
			alert("指标名称已经存在，请修改");
			return;
		}
		var expression1 = $.trim($("#expression").val());
		if (!expression1) {
			alert("必须输入自定义操作");
			return;
		}
		var expval = document.getElementById("expression").value;
		if (!/#([^#]+)#/.test(expval)) {
			//alert("请至少选择一个指标");
			//return ;
		}
		var cstm = expval.replace(/#([^#]+)#/g, function() {
			var code = nameMap[arguments[1]];
			if (code === undefined) {
				alert("计算公式有误，请重新编辑！");
				return 'empty_error';
			} else if (code.indexOf("#") === 0 || code.indexOf("(") === 0) {
				return "(" + code + ")";
			}
			return "#" + code + "#";
		});
		if (cstm.indexOf('empty_error') === -1) {
			addExpression.push(cstmName + ":" + cstm);
		}
		processDate(cstmName,cstm);
	}

	function processDate(cstmName, cstm){
		var count = 0;
		var falg = false;
		var Id = "";
		var Ids = new Array();
		var number = "";
		for(i = 0; i < cstm.length; i++){
			var charAt = cstm.charAt(i);
			if(charAt == '#'){
				if(number != ""){
					Ids.push(number);
					number = "";
				}
				count++;
				flag = true;
				if(count>0 && count%2 == 0){
					if(Id != ""){
						Ids.push(Id);
					}
					flag = false;
					Id = "";
				}
			}else{
				if(count%2 == 0){
					flag = false;
					if(charAt=='+' || charAt=='-' || charAt=='*' || charAt=='/'){
						if(number != ""){
							Ids.push(number);
						}
						Ids.push(charAt);
						number = "";
					}else{
						number = number + charAt;
					}
					if(i == cstm.length-1){
						if(number != ""){
							Ids.push(number);
							number = "";
						}
					}
				}
				if(flag){
					Id=Id+charAt; 
				}
			}
		}
		fillDate(cstmName,Ids);
	}
	
	